var XHR;
function downloads(that) {
    window.open($(that).attr('data-url'))
}
var boxStyle = GetQueryString('boxStyle');
var otherBoxId = GetQueryString('id');
var pageNum = 1;
var pageTotao = 0;
var userCookie = $.cookie('userId');
var ue;
$(function () {
    var data1 = {
        "flag": 'inbox',
        "page": pageNum,
        "pageSize": 15,
        "useFlag": true,
        "searchCriteria": '',
        "orderByName": '',
        "orderWhere": '',
        "isWebmail": ''
    };
    var data2 = {
        "flag": 'drafts',
        "page": pageNum,
        "pageSize": 15,
        "useFlag": true,
        "searchCriteria": '',
        "orderByName": '',
        "orderWhere": '',
    };
    var data3 = {
        "flag": 'outbox',
        "page": pageNum,
        "pageSize": 15,
        "useFlag": true,
        "searchCriteria": '',
        "orderByName": '',
        "orderWhere": '',
        "isWebmail": ''
    };
    var data4 = {
        "flag": 'recycle',
        "page": pageNum,
        "pageSize": 15,
        "useFlag": true,
        "searchCriteria": '',
        "orderByName": '',
        "orderWhere": '',
        "isWebmail": ''
    };
    var data5 = {
        'page': pageNum,
        'pageSize': 15,
        'useFlag': false,
        'boxId': otherBoxId,
        "searchCriteria": '',
        "orderByName": '',
        "orderWhere": ''
    }
    if (boxStyle == 'inbox') {  //收件箱

        showAjax(data1, 'newShowEmail');
        $('.getUser').show();

    } else if (boxStyle == 'drafts') {  //草稿箱

        $('.getUser').hide();
        showAjax(data2, 'newShowEmail');
    } else if (boxStyle == 'outbox') {  //已发送

        $('.getUser').hide();
        showAjax(data3, 'newShowEmail');
    } else if (boxStyle == 'recycle') {  //废纸篓

        $('.getUser').hide();
        showAjax(data4, 'newShowEmail');
    } else if (boxStyle == 'otherBox') {  //其他邮件箱

        $('.getUser').hide();
        showAjax(data5, 'selectBoxEmail');
    } else if (boxStyle == 'unreadBox') {
        $('.getUser').hide();
        data1.flag = 'inboxNoRead';
        showAjax(data1, 'newShowEmail');
    }
    var timer = null;
    $('#befor').scroll(function () {
        var wholeHeight = $(this)[0].scrollHeight;
        var scrollTop = $(this)[0].scrollTop;
        var divHeight = $(this)[0].clientHeight;
        var iNows = Math.ceil(pageTotao / 15);

        var liLIst = $('.signDiv').find('li');

        if (divHeight + scrollTop >= wholeHeight) {
            clearTimeout(timer);
            timer = setTimeout(function () {
                if (boxStyle == 'inbox') {  //收件箱
                    ++data1.page;
                    if (data1.page > iNows) {
                        return false;
                    }
                    showAjax(data1, 'newShowEmail');
                    $('.getUser').show();
// 滚动条到最底下，加载出来的邮件默认全选
                    if ($('.chekEmail').prop('checked') == true) {
                        $('.chekEmail').show();
                        $('.chekEmail').prop('checked', true);
                        if (boxStyle == 'inbox') {
                            $('#Replay', parent.document).hide();
                            $('#ReplayAll', parent.document).hide();
                        }
                    } else {
                        $('.chekEmail').prop('checked', false);
                        $('.chekEmail').hide();
                        if (boxStyle == 'inbox') {
                            $('#Replay', parent.document).show();
                            $('#ReplayAll', parent.document).show();
                        }
                    }

                } else if (boxStyle == 'drafts') {  //草稿箱
                    ++data2.page;
                    if (data2.page > iNows) {
                        return false;
                    }
                    $('.getUser').hide();
                    showAjax(data2, 'newShowEmail');
                } else if (boxStyle == 'outbox') {  //已发送
                    ++data3.page;
                    if (data3.page > iNows) {
                        return false;
                    }
                    $('.getUser').hide();
                    showAjax(data3, 'newShowEmail');
                } else if (boxStyle == 'recycle') {  //废纸篓
                    ++data4.page;
                    if (data4.page > iNows) {
                        return false;
                    }
                    $('.getUser').hide();
                    showAjax(data4, 'newShowEmail');
                } else if (boxStyle == 'otherBox') {  //其他邮件箱
                    ++data5.page;
                    if (data5.page > iNows) {
                        return false;
                    }
                    $('.getUser').hide();
                    showAjax(data5, 'selectBoxEmail');
                }
            }, 500);

        }

    });

//详情点击事件
    $('.main_left').on('click', '.BTN', function () {

        /*if ($(this).attr('class').indexOf('backing') > -1) {
        return false;
        }*/
        $(this).addClass("backing").siblings().removeClass("backing");
        var nId = $(this).find('input').attr('id');
        var readf = $(this).find('input').attr('readf');
        var bodyNid = $(this).find('input').attr('nId');
        var fromId = $(this).attr('fromId');
        var detailData = {
            emailId: nId,
            flag: ''
        }
        if (boxStyle == 'inbox' || boxStyle == 'unreadBox') {
            var noReadel = {
                flag: 'isRead',
                emailId: nId
            }
            if (readf == '0') {
                initData(noReadel);
// $(this).find('.noReadF').attr('src','../img/icon_read_2_03.png');
                $(this).find('.noReadF').attr('src', '');
            } else {
                initData(detailData);
            }
            getUserInfo_s(fromId)
        } else if (boxStyle == 'drafts') {
            $('.getUser').hide();
            initDrafts(bodyNid);
        } else if (boxStyle == 'outbox') {
            $('.getUser').hide();
            var detailOutbox = {
                bodyId: bodyNid,
                flag: ''
            }
            initData(detailOutbox);
        } else if (boxStyle == 'recycle') {
            $('.getUser').hide();
            initData(detailData);
        } else if (boxStyle == 'otherBox') {
            $('.getUser').hide();
            var detailOtherBox = {
                emailId: nId,
                flag: ''
            }
            initData(detailOtherBox);
        }

    });

//点击搜索图标
    $('.Search').click(function () {
        $('.search_div').toggle();
    })

//搜索结果方法
    $('.searchTxt').bind('input propertychange', function () {
        var valN = $(this).val();

        if (boxStyle == 'inbox') {  //收件箱
            data1.searchCriteria = valN;
            data1.page = 1;
            showAjaxPaixu(data1, 'newShowEmail');
            $('.getUser').show();

        } else if (boxStyle == 'drafts') {  //草稿箱
            data2.searchCriteria = valN;
            data2.page = 1;
            $('.getUser').hide();
            showAjaxPaixu(data2, 'newShowEmail');
        } else if (boxStyle == 'outbox') {  //已发送
            data3.searchCriteria = valN;
            data3.page = 1;
            $('.getUser').hide();
            showAjaxPaixu(data3, 'newShowEmail');
        } else if (boxStyle == 'recycle') {  //废纸篓
            data4.searchCriteria = valN;
            data4.page = 1;
            $('.getUser').hide();
            showAjaxPaixu(data4, 'newShowEmail');
        } else if (boxStyle == 'otherBox') {  //其他邮件箱
            data5.searchCriteria = valN;
            data5.page = 1;
            $('.getUser').hide();
            showAjaxPaixu(data5, 'selectBoxEmail');
        }
    });

//取消搜索按钮
    $('.cancleSpan').click(function () {
        $('.searchTxt').val('');
        $('.search_div').hide();
        if (boxStyle == 'inbox') {  //收件箱
            data1.searchCriteria = '';
            showAjaxPaixu(data1, 'newShowEmail');
            $('.getUser').show();
        } else if (boxStyle == 'drafts') {  //草稿箱
            data2.searchCriteria = '';
            $('.getUser').hide();
            showAjaxPaixu(data2, 'newShowEmail');
        } else if (boxStyle == 'outbox') {  //已发送
            data3.searchCriteria = '';
            $('.getUser').hide();
            showAjaxPaixu(data3, 'newShowEmail');
        } else if (boxStyle == 'recycle') {  //废纸篓
            data4.searchCriteria = '';
            $('.getUser').hide();
            showAjaxPaixu(data4, 'newShowEmail');
        } else if (boxStyle == 'otherBox') {  //其他邮件箱
            data5.searchCriteria = '';
            $('.getUser').hide();
            showAjaxPaixu(data5, 'selectBoxEmail');
        }
    })


//刷新点击事件
    $('.ReFresh').click(function () {
        if (boxStyle == 'inbox') {  //收件箱
// showAjax(data1,'showEmail');
            showAjaxPaixu(data1, 'newShowEmail');
            $('.getUser').show();
        } else if (boxStyle == 'drafts') {  //草稿箱
            $('.getUser').hide();
// showAjax(data2,'showEmail');
            showAjaxPaixu(data2, 'newShowEmail');
        } else if (boxStyle == 'outbox') {  //已发送
            $('.getUser').hide();
// showAjax(data3,'showEmail');
            showAjaxPaixu(data3, 'newShowEmail');
        } else if (boxStyle == 'recycle') {  //废纸篓
            $('.getUser').hide();
// showAjax(data4,'showEmail');
            showAjaxPaixu(data4, 'newShowEmail');
        } else if (boxStyle == 'otherBox') {  //其他邮件箱
            $('.getUser').hide();
// showAjax(data5,'selectBoxEmail');
            showAjaxPaixu(data5, 'selectBoxEmail');
        }
    })

//标记已读
    $('.signReaders').click(function () {
        $('.chekEmail').prop('checked', false);
        $('.chekEmail').toggle();
    })

//一键全选
    $('.selectReaders').click(function () {
        if ($('.chekEmail').prop('checked') == true) {
            $('.chekEmail').prop('checked', false);
            $('.chekEmail').hide();
            if (boxStyle == 'inbox') {
                $('#Replay', parent.document).show();
                $('#ReplayAll', parent.document).show();
            }
        } else {
            $('.chekEmail').show();
            $('.chekEmail').prop('checked', true);
            if (boxStyle == 'inbox') {
                $('#Replay', parent.document).hide();
                $('#ReplayAll', parent.document).hide();
            }
        }
    })
//排序图标点击
    $('.sort_right').click(function (e) {
        e.stopPropagation();
        $('.signDiv').toggle();
    })
    var orderNameStr = "";
    var oWhereStr = "";
//排序内容点击
    $('.signDiv').on('click', 'li', function () {
        $(this).addClass('bgSort').siblings().removeClass('bgSort');
// orderNameStr=$(this).attr('orderByName');
// oWhereStr=$(this).attr('orderWhere');
        orderNameStr = $('#orderByName').find('.bgSort').attr('orderByName');
        oWhereStr = $('#orderWhere').find('.bgSort').attr('orderWhere');
        var id = $('.divUlShow').find('li.on').attr('boxid');
        if (boxStyle == 'inbox') {  //收件箱
            data1.orderByName = orderNameStr;
            data1.orderWhere = oWhereStr;
            showAjaxPaixu(data1, 'newShowEmail');
            $('.getUser').show();
        } else if (boxStyle == 'drafts') {  //草稿箱
            data2.orderByName = orderNameStr;
            data2.orderWhere = oWhereStr;
            $('.getUser').hide();
            showAjaxPaixu(data2, 'newShowEmail');
        } else if (boxStyle == 'outbox') {  //已发送
            data3.orderByName = orderNameStr;
            data3.orderWhere = oWhereStr;
            $('.getUser').hide();
            showAjaxPaixu(data3, 'newShowEmail');
        } else if (boxStyle == 'recycle') {  //废纸篓
            data4.orderByName = orderNameStr;
            data4.orderWhere = oWhereStr;
            $('.getUser').hide();
            showAjaxPaixu(data4, 'newShowEmail');
        } else if (boxStyle == 'otherBox') {  //其他邮件箱
            data5.orderByName = orderNameStr;
            data5.orderWhere = oWhereStr;
            $('.getUser').hide();
            showAjaxPaixu(data5, 'selectBoxEmail');
        }
        $('.signDiv').hide();
    })
    $('.a1').click(function () {
        var str = '<tr class="tian"><td>' + email_th_carbonCopyRecipients + '：</td><td><textarea disabled id="copeNameText" name="txt"></textarea><span class="add_img"><a class="Add" href="javascript:;" id="selectUserO" style="margin-left: 16px;font-size: 14px;">' + global_lang_add + '</a></span><span class="add_img"><a class="clearCC" href="javascript:;" style="margin-left: 16px;font-size: 14px;">' + notice_th_delete1 + '</a></span></td></tr>';
        var txt = $(this).text();
        if (txt == email_th_addwait) {//添加抄送
            $(this).text(email_th_HideCC);//隐藏抄送
            $('.append_tr').after(str);
        } else {
            $(this).text(email_th_addwait);//添加抄送
            $('.tian').remove();
        }
    })

    $('.a2').click(function () {
        var str = '<tr class="mis"><td>' + email_th_BlindPeople + '：</td><td><textarea disabled id="secritText" name="txt"></textarea><span class="add_img"><a class="Add" href="javascript:;" id="selectUserT" style="margin-left: 16px;font-size: 14px;">' + global_lang_add + '</a></span><span class="add_img"><a class="clearBCC" href="javascript:;" style="margin-left: 16px;font-size: 14px;">' + notice_th_delete1 + '</a></span></td></tr>';
        var txt = $(this).text();
        if (txt == email_th_addbcc) {//添加密送
            $(this).text(email_th_HiddenSecret);//隐藏密送
            $('.append_tr').after(str);
        } else {
            $(this).text(email_th_addbcc);//添加密送
            $('.mis').remove();
        }
    })
    $('.a3').click(function(){
// var str='<tr class="InText"><td style="padding: 5px;">'+InEmali+'：</td><td style="padding: 5px;"><select><option value="1729562020@qq.com">1729562020@qq.com</option><option value="845708329@qq.com">845708329@qq.com</option></select><span>'+sendMail+'</span></td></tr>';
        var txt=$(this).text();
        if (txt=='添加外部收件人') {
            $(this).text('隐藏外部收件人');
            $('.InText').show();
            $(this).attr('a3Type','1')
        }else{
            $(this).text('添加外部收件人');
            $('.InText').hide();
            $(this).attr('a3Type','0')
        }
    })
})
function emailText(text) {
    var emailText=text;
	/*if(emailText.length>15){
        emailText=emailText.substring(0,15);
        return emailText+"......";
    }else {
        return emailText;
    }*/
    return text;
}
//邮件列表
function showAjax(dataId, emailUrl) {
// $('.befor').find('li').remove();
    var ajaxPage = {
        data: dataId,
        page: function () {
            var me = this;
            $.ajax({
                type: 'get',
                url: emailUrl,
                dataType: 'json',
                data: me.data,
                success: function (res) {
                    var data1 = res.obj;
                    var str = '';
                    var dataNUm = res.object;
                    pageTotao = res.totleNum;
                    $('#inboxNum', parent.document).html(res.inboxCount);
                    $('#draftsNum', parent.document).html(res.draftsCount);
                    $('#hasBeenSendNum', parent.document).html(res.hairboxCount);
                    $('#wastebasketNum', parent.document).html(res.wasteCount);
                    $('#unreadNum', parent.document).html(res.noReadCount);
                    if(res.noReadCount==0){
                        $('#unreadNum', parent.document).css("background","none")

                    }else{
                        $('#unreadNum', parent.document).css("background","url(../../img/icon_juxing.png) no-repeat")
                    }
                    if (data1.length > 0) {
                        $('.befor').show();
                        $('.noContent').hide();
                        $('.noEmail').hide();
                        for (var i = 0; i < data1.length; i++) {
                            var sendTime = new Date((data1[i].sendTime) * 1000).Format('yyyy-MM-dd hh:mm');
                            var emailSubject = '';
                            if (data1[i].emailList[0].withdrawFlag == undefined || data1[i].emailList[0].withdrawFlag == '0') {
                                emailSubject = data1[i].subject;
                                emailSubject=emailText(emailSubject)
                            } else {
                                emailSubject = retuened + ':' + data1[i].subject;
                                emailSubject=emailText(emailSubject)
                            }
                            var toNames = (data1[i].toName).split(',');
                            var toNameId = (data1[i].toId2).split(',');
                            str += '<li class="BTN" fromId="' + data1[i].fromId + '" style="cursor: pointer;text-align: left;height: 44px">' +
                                '<input emailId="' + data1[i].emailList[0].emailId + '" id="' + data1[i].emailList[0].emailId + '" nId="' + data1[i].bodyId + '" readF="' + data1[i].emailList[0].readFlag + '"  type="hidden" ueId="' + data1[i].emailList[0].deleteFlag + '">' +
                                '<input checkId="' + data1[i].bodyId + '" class="chekEmail" emailId="' + data1[i].emailList[0].emailId + '" style="width:16px;display:none;" type="checkbox">' +
								'<div style="float:left;height:100%;padding:0 5px 0 0;"><img style="height:44px;width:44px;margin:0px;border-radius:100%;" src="/img/user/' + function () {
                                    if (data1[i].users.avatar != ''&&data1[i].users.avatar != '0') {
                                        return data1[i].users.avatar;
                                    } else if (data1[i].users.sex == 0) {
										 return 'boy.png';
                                    } else {
                                        return 'girl.png';
                                    }
                                }() + '"></div>'+
  							    '<div class="shang" style="display: inline;">' +
                                '<span style="margin-left:2%">' + function () {
                                    if (dataId.flag == 'inbox') {
                                        return returnUserName(data1[i].users);
                                    } else if (dataId.flag == 'outbox') {
                                        if (data1[i].toName == '') {
                                            return toNameId[0];
                                        } else {
                                            return toNames[0];
                                        }
                                    } else {
                                        return data1[i].users.userName;
                                    }
                                }() + '</span>' +
                                function () {
                                    if (boxStyle == 'inbox' || boxStyle == 'unreadBox') {
                                        if (data1[i].emailList[0].readFlag == '1') {
                                            return '';
                                        } else {
                                            return '<span class="fa fa-envelope noReadF" ></span>';
                                        }
                                    } else {
                                        // return '<img src="../img/readed.png"/>';
                                        return '';
                                    }
                                }() +
                                '<span class="time">' + sendTime + '</span>' +
                                '</div>' +
                                '<div class="xia" style="white-space:nowrap; overflow:hidden;text-overflow:ellipsis;">' +
                                '<span style="float: left;margin-left: 13px;margin-right: 4px;">' + function () {
                                    if (data1[i].attachmentId != '' && data1[i].emailList[0].withdrawFlag != '1') {
                                        //return '<img src="/img/main_img/accessory.png" style="margin-right:85.8%;width: 11px;height: 15px;"/>';
                                        return '<i class="fa fa-paperclip"></i>';
                                    }else {
                                        return '';
                                    }
                                }() + '</span>' +
                                '<a class="xia_txt a-xiaTexti" href="javascript:;" style="-webkit-line-clamp:2;overflow: hidden;-webkit-box-orient: vertical;margin-left: 10px;display: inline;">' + emailSubject + '</a>' +
                                '</div>' +
                                '</li>';
                        }
                        $('.befor').append(str);
                        $('li.BTN').eq(0).addClass("backing");
                        if (boxStyle == 'inbox' || boxStyle == 'unreadBox') {
                            $('li.BTN').eq(0).click();
                        }

                        $('li.BTN').eq(0).find(".noReadF").attr('src', '');

                        var emailId = $('.befor .backing').find('input[type="hidden"]').attr('id');
                        var bodyNid = $('.befor .backing').find('input').attr('nId');
                        if (boxStyle == 'inbox' || boxStyle == 'unreadBox') {
                            var formIds = $('.befor .backing').attr('fromid');
                            var detailData = {
                                emailId: emailId,
                                flag: 'isRead'
                            }
                            $('.detailes').show();
                            $('.drafts').hide();
                            getUserInfo_s(formIds);
                            initData(detailData);
                        } else if (boxStyle == 'drafts') {
                            $('.detailes').hide();
                            $('.drafts').show();
                            initDrafts(bodyNid);

                        } else if (boxStyle == 'outbox') {
                            $('.getUser').hide();
                            $('.detailes').show();
                            $('.drafts').hide();
                            var detailOutbox = {
                                bodyId: bodyNid,
                                flag: ''
                            }
                            initData(detailOutbox);
                        } else if (boxStyle == 'recycle') {

                            $('.getUser').hide();
                            $('.detailes').show();
                            $('.drafts').hide();
                            var detailRecycle = {
                                emailId: emailId,
                                flag: ''
                            }
                            initData(detailRecycle);
                        } else if (boxStyle == 'otherBox') {
                            $('.getUser').hide();
                            $('.detailes').show();
                            $('.drafts').hide();
                            var detailOtherBox = {
                                emailId: emailId,
                                flag: ''
                            }
                            initData(detailOtherBox);
                        }
                    } else {
                        $('.befor').hide();
                        $('.noContent').show();
                        $('.noEmail').show().siblings().hide();
                    }
// me.pageTwo(res.totleNum,me.data.pageSize,me.data.page)
                }
            })

        },
        pageTwo: function (totalData, pageSize, indexs) {
            var mes = this;
            $('#dbgz_page').pagination({
                totalData: totalData,
                showData: pageSize,
                jump: true,
                coping: true,
                homePage: '',
                endPage: '',
                current: indexs || 1,
                callback: function (index) {
                    mes.data.page = index.getCurrent();
                    mes.page();
                }
            });
        }
    };
    ajaxPage.page();
}

function yd(e) {
    var atturl = e.attr('attrurl');
    $.pdurl($.UrlGetRequest('?' + atturl), atturl);
}
//收件箱、已发送、废纸篓详情展示
function initData(datas) {
    layer.load();
    $('.detailes').find('#TAB').remove();
    $('.detailes').find('.article').remove();
    if (XHR) {
        XHR.abort();
    }
    XHR = $.ajax({
        type: 'get',
        url: 'queryByID',
        dataType: 'json',
        data: datas,
        success: function (rsp) {
// console.log(XHR);
            $('.detailes').find('#TAB').remove();
            $('.detailes').find('.article').remove();
            var data2 = rsp.object;
            if (!data2 || data2.length <= 0) {
                return;
            }
            var sendTime = new Date((data2.sendTime) * 1000).Format('yyyy-MM-dd hh:mm:ss');
            var object = '';
            var stra = '';
            var arr = new Array();
            arr = data2.attachment;
            var content = '';
            if (data2.emailList[0].withdrawFlag == '0') {
                var contentMsg = data2.content;
                if (contentMsg.indexOf('iframe') > -1) {
                    var cm = $('<div>' + contentMsg.toString() + '</div>');
                    cm.find('iframe').remove();
                    contentMsg = cm.html();
                }
                content = contentMsg;
            } else {
                content = sysLdering;
            }

            var emailSubject = '';
            if (data2.emailList[0].withdrawFlag == undefined || data2.emailList[0].withdrawFlag == '0') {
                emailSubject = data2.subject;
                emailSubject=emailText(emailSubject)
            } else {
                emailSubject = retuened + ':' + data2.subject;
                emailSubject=emailText(emailSubject)
            }
            object += '<table cellpadding="0" cellspacing="0" id="TAB" style="border-collapse:collapse;table-layout: fixed;">' +
                '<tr>' +
                '<td style="width:70px;">' + email_th_main + '：</td>' +
                '<td style="display:block;white-space:nowrap; overflow:hidden; text-overflow:ellipsis;" title="' + data2.subject + '" width="100%">' +
                '<div style="width:60%;width: calc(100% - 200px);display:block;white-space:nowrap; overflow:hidden; text-overflow:ellipsis;" title="' + data2.subject + '">' + emailSubject + '</div>' +
                '</td></tr>' +  //主题
                '<tr><td>' + email_th_sender + '：</td><td>' + data2.users.userName + '</td></tr>' +  //发件人
                '<tr><td>' + email_th_recipients + '：</td>' +
                '<td><span class="isReaderType" style="display: inline-block;" title="' + data2.toName + '">' + function () {
                    if (data2.toUserEmailInfo) {
                        var userStr = "";

                        for (var i = 0; i < data2.toUserEmailInfo.length; i++) {
                            if (i > 2) {
                                userStr += "...";
                                break;
                            }
                            if (data2.toUserEmailInfo[i].readFlag == '1') {
                                userStr += '<span class="fa fa-envelope-open" ></span><span style="margin-right: 10px;">' + data2.toUserEmailInfo[i].userName + '</span>'
                            } else {
                                userStr += '<span class="fa fa-envelope" ></span><span style="margin-right: 10px;">' + data2.toUserEmailInfo[i].userName + '</span>'
                            }
                        }
                        return userStr;
                    }
                }() + '</span>' +
                '<a href="/email/emailReadDetail?bodyId=' + data2.bodyId + '&userIdsType=toId2" target="_blank" urls="">' + event_th_ViewMailStatus + '</a></td></tr>'
            if (data2.copyName != '') {
                object += '<tr><td>' + email_th_carbonCopyRecipients + '：</td>' +
                    '<td><span class="copyType" style="display: inline-block;min-width: 240px;width:30%;" title="' + data2.copyName + '">' + function () {
                        var copyUserStr = "";
                        if (data2.copyUserEmailInfo) {
                            for (var i = 0; i < data2.copyUserEmailInfo.length; i++) {
                                if (i > 2) {
                                    copyUserStr += "...";
                                    break;
                                }
                                if (data2.copyUserEmailInfo[i].readFlag == '1') {
                                    copyUserStr += '<span class="fa fa-envelope-open"></span><span style="margin-right: 10px;">' + data2.copyUserEmailInfo[i].userName + '</span>'
                                } else {
                                    copyUserStr += '<span class="fa fa-envelope" ></span><span style="margin-right: 10px;">' + data2.copyUserEmailInfo[i].userName + '</span>'
                                }
                            }
                            return copyUserStr;
                        }
                    }() + '</span>' +
                    '<a href="/email/emailReadDetail?bodyId=' + data2.bodyId + '&userIdsType=copyToId" target="_blank" urls="">' + event_th_ViewMailStatus + '</a>' +
                    '</td></tr>';
            }
            if (data2.secretToName != '') {
                object += '<tr><td>' + email_th_BlindPeople + '：</td>' +
                    '<td><span class="secrCopy" style="display: inline-block;min-width: 240px;width:30%;">' + function () {
                        var secrUserStr = "";
                        if (data2.sercUserEmailInfo) {
                            for (var i = 0; i < data2.sercUserEmailInfo.length; i++) {
                                if (i > 2) {
                                    secrUserStr += "...";
                                    break;
                                }
                                if (data2.sercUserEmailInfo[i].readFlag == '1') {
                                    secrUserStr += '<img src="../img/readed.png" /><span style="margin-right: 10px;">' + data2.sercUserEmailInfo[i].userName + '</span>'
                                } else {
                                    secrUserStr += '<img class="noReadF" src="../img/unread.png"/><span style="margin-right: 10px;">' + data2.sercUserEmailInfo[i].userName + '</span>'
                                }
                            }
                            return secrUserStr;
                        }
                    }() + '</span>' +
                    '<a href="/email/emailReadDetail?bodyId=' + data2.bodyId + '&userIdsType=secretToId" target="_blank" urls="">' + event_th_ViewMailStatus + '</a>' +
                    '</td></tr>'
            }
            object += '<tr><td>' + email_th_time + '：</td><td>' + sendTime + '</td></tr>'



            if (data2.attachment.length > 0) {
                if(data2.attachment.length > 1){
                    var manydownload = '<a class="operation batch" href="javascript:void(0);"><span class="fa fa-arrow-alt-to-bottom" style="margin-right: 5px;" alt=""></span>批量下载</a>';
                }else{
                    var manydownload = ''
                }
                object += '<tr><td>' + email_th_file + '：</td><td class="attachment" id="operationImg2">' + attachView(arr, '', '4', '0', '1', '0') + '<div>'+ manydownload +'</div></td></tr>';

            }
            object += '</table>' +
                '<div class="article"><p>' + content + '</p></div>';

            $('.detailes').append(object);
            $('.operationImg').click(function(){
// $(document).on('click','.operationImg',function () {
                var thisa = $(this).next().attr('openimg')
                var openNmu = $(this).next().attr('openNmu')
                var str3 = '<input id="getIndex" openNum = "'+openNmu+'" style="display: none" type="text">'
                $('#operationImg2').append(str3)
                $('#getIndex').val(thisa)
                console.log(openNmu)
                event.stopPropagation()
                window.open("/email/imgOpen?openNmu="+openNmu,"_blank");
// layer.open({
//     title:'图片',
//     type: 2,
//     shadeClose: true,
//     shade: 0.5,
//     maxmin: true, //开启最大化最小化按钮
//     area: ['100%', '100%'],
//     content: '/email/imgOpen',
//     success: function () {
//
//     }
// });
            })


// $('.batch').click(function () {
//     for (var i = 0; i < $('.attachment .font_').length; i++) {
//         var atturl = $('.attachment .font_ ').children('.download').eq(i).attr('href');
//         window.open(encodeURI(atturl));
//     }
// })
            $('.batch').click(function () {
                var str = '';
                for(var i=0;i<arr.length;i++){
                    str+= arr[i].aid+','
                }
                var nowTime = new Date().toLocaleString();
                var toyear = nowTime.substring(0,6);
                var today =  nowTime.substring(7,11);
                var Nowadays = '邮件批量下载'
                window.location.href='/getZipFilename?aId='+str+'&module=email&zipName='+encodeURI(Nowadays);

            })
            var toUserArrId = [];
            var copyUserArrId = [];
            var sercUserArrId = [];
            var indextoUser = -1;
            var indexcopyUser = -1;
            var indexsercUser = -1;
            if (data2.toUserEmailInfo) {
                for (var i = 0; i < data2.toUserEmailInfo.length; i++) {
                    toUserArrId.push(data2.toUserEmailInfo[i].toId)
                }

                if (toUserArrId.toString().indexOf(userCookie) > -1) {
                    for (var i = 0; i < toUserArrId.length; i++) {
                        if (toUserArrId[i] == userCookie) {
                            indextoUser = i;
                            break;
                        }
                    }
                    $('.isReaderType').find('img').eq(indextoUser).attr('class', 'fa-envelope-open');
                }

            }
            if (data2.copyUserEmailInfo) {
                for (var i = 0; i < data2.copyUserEmailInfo.length; i++) {
                    copyUserArrId.push(data2.copyUserEmailInfo[i].toId)
                }
                if (copyUserArrId.toString().indexOf(userCookie) > -1) {
                    for (var i = 0; i < copyUserArrId.length; i++) {
                        if (copyUserArrId[i] == userCookie) {
                            indexcopyUser = i;
                            break;
                        }
                    }
                    $('.copyType').find('img').eq(indexcopyUser).attr('class', 'fa-envelope-open');
                }
            }
            if (data2.sercUserEmailInfo) {
                for (var i = 0; i < data2.sercUserEmailInfo.length; i++) {
                    sercUserArrId.push(data2.sercUserEmailInfo[i].toId)
                }
                if (sercUserArrId.toString().indexOf(userCookie) > -1) {
                    for (var i = 0; sercUserArrId.length; i++) {
                        if (sercUserArrId[i] == userCookie) {
                            indexsercUser = i;
                            break;
                        }
                    }
                    $('.secrCopy').find('img').eq(indexsercUser).attr('src', '../img/readed.png');
                }
            }
            var Height = $('.detailes').height() - $('#TAB').height() - 46;
            $('.article').height(Height + 'px');

            $('.imgfileBox').css("margin-left", "25px")
            $('.imgfileBox').append('<ul class="hoverbox"><li class="hoverboxLiConsult"><span class="plotting">></span>查阅</li><li class="hoverboxLiDownload"><span class="plotting">></span>下载</li></ul>')
            $('.imgfileBox').mouseover(function () {
                if ($(this).children('.hoverbox').length > 0) {
                    $(this).children('.hoverbox').eq($(this).children('.hoverbox').length - 1).show();
                }
            });
            $('.imgfileBox').mouseout(function () {
                if ($(this).children('.hoverbox').length > 0) {
                    $(this).children('.hoverbox').eq($(this).children('.hoverbox').length - 1).hide();
                }

            });
            $('.imgfileBox').on('click', '.hoverboxLiDownload', function () {
                var atturl = $(this).parents('.imgfileBox').find('img').attr('atturl')
                if (atturl == '' || atturl == undefined) {
                    window.open("/download?" + encodeURI($(this).parents('.imgfileBox').find('img').attr('src')));
                } else {
                    window.location.href = "/download?" + encodeURI(atturl);
                }
            })
            $('.imgfileBox').on('click', '.hoverboxLiConsult', function () {
                var str = $(this).parents('.imgfileBox').find('img').attr('atturl');
                var fileURl = $(this).parents('.imgfileBox').find('span').attr('title')
                var fileExtension = fileURl.substring(fileURl.lastIndexOf(".") + 1, fileURl.length);//截取附件文件后缀
                pdurl(fileExtension, str);
            });
            layer.closeAll()
        }
    });
}
//草稿箱详情展示
function initDrafts(nId) {
    $.ajax({
        type: 'get',
        url: 'queryByID',
        dataType: 'json',
        data: {'bodyId': nId, 'flag': ''},
        success: function (rsp) {
            if (rsp.flag == true) {
//			附件上传方法
                fileuploadFn('#uploadinputimg', $('.Attachment td').eq(1));

                var data2 = rsp.object;
                if (!data2 || data2.length <= 0) {
                    return;
                }
                var atta = data2.attachment;
                var str = '';
                $('.tian').remove();
                $('.mis').remove();

                $('textarea').val('');
                $('#txt').val('');


                $('#senduser').val('');
                $('.Attachment td').eq(1).find('div').remove();
                for (var i = 0; i < atta.length; i++) {
                    str += '<div class="dech" deUrl="' + encodeURI(atta[i].attUrl) + '">' +
                        '<a NAME="' + atta[i].attachName + '*" href="/download?' + encodeURI(atta[i].attUrl) + '" style="text-decoration:none;margin-left:5px;">' +
                        '<img src="../img/attachment_icon.png" style="margin-right:10px;"/>' + atta[i].attachName + '</a>' +
                        '<img class="deImgs" src="../img/file/icon_deletecha_03.png" style="margin-left:5px;cursor: pointer;"/>' +
                        '<input class="inHidden" type="hidden" value="' + atta[i].aid + '@' + atta[i].ym + '_' + atta[i].attachId + ',">' +
                        '</div>';
                }
                $('.Attachment td').eq(1).append(str);
                $('#senduser').val(data2.toName);
                $('#senduser').attr('user_id', data2.toId2);
                if (data2.copyToId != '') {
                    var cStr = '';
                    cStr = '<tr class="tian"><td>' + email_th_carbonCopyRecipients + '：</td><td><textarea disabled id="copeNameText" name="txt"></textarea><span class="add_img"><a class="Add" href="javascript:;" id="selectUserO" style="margin-left: 5px;">' + global_lang_add + '</a></span><span class="add_img"><a class="clearCC" href="javascript:;" style="margin-left: 5px;">' + notice_th_delete1 + '</a></span></td></tr>';
                    $('.a1').text(email_th_HideCC);
                    $('.append_tr').after(cStr);
                    $('#copeNameText').attr('user_id', data2.copyToId + ',');
                    $('#copeNameText').val(data2.copyName);
                }
                if (data2.secretToId != '') {
                    var sStr = '';
                    sStr = '<tr class="mis"><td>' + email_th_BlindPeople + '：</td><td><textarea disabled id="secritText" name="txt"></textarea><span class="add_img"><a class="Add" href="javascript:;" id="selectUserT" style="margin-left: 5px;">' + global_lang_add + '</a></span><span class="add_img"><a class="clearBCC" href="javascript:;" style="margin-left: 5px;">' + notice_th_delete1 + '</a></span></td></tr>';
                    $('.a2').text(email_th_HiddenSecret);//'隐藏密送'
                    $('.append_tr').after(sStr);
                    $('#secritText').attr('user_id', data2.secretToId + ',');
                    $('#secritText').val(data2.secretToName);
                }
                $('#txt').val(data2.subject);
                ue = UE.getEditor('container',{elementPathEnabled : false});
                UEimgfuc();


                ue.addListener("ready", function () {
// editor准备好之后才可以使用
                    ue.setContent('');
                    if (ue.setContent) {
                        ue.setContent(data2.content);
                    }
                });
            }
        }
    });
}


//排序列表
function showAjaxPaixu(dataId, emailUrl) {
// $('.befor').find('li').remove();
    var ajaxPage = {
        data: dataId,
        page: function () {
            var me = this;
            $.ajax({
                type: 'get',
                url: emailUrl,
                dataType: 'json',
                data: me.data,
                success: function (res) {
                    var data1 = res.obj;
                    var str = '';
                    var dataNUm = res.object;
                    pageTotao = res.totleNum;
                    $('#inboxNum', parent.document).html(res.inboxCount);
                    $('#draftsNum', parent.document).html(res.draftsCount);
                    $('#hasBeenSendNum', parent.document).html(res.hairboxCount);
                    $('#wastebasketNum', parent.document).html(res.wasteCount);
                    if (data1.length > 0) {
                        $('.befor').show();
                        $('.noContent').hide();
                        $('.noEmail').hide();
                        for (var i = 0; i < data1.length; i++) {
                            var sendTime = new Date((data1[i].sendTime) * 1000).Format('yyyy-MM-dd hh:mm');
                            var emailSubject = '';
                            var toNames = (data1[i].toName).split(',');
                            var toNameId = (data1[i].toId2).split(',');
                            if (data1[i].emailList[0].withdrawFlag == undefined || data1[i].emailList[0].withdrawFlag == '0') {
                                emailSubject = data1[i].subject;
                                emailSubject=emailText(emailSubject)
                            } else {
                                emailSubject = retuened + ':' + data1[i].subject;
                                emailSubject=emailText(emailSubject)
                            }
                            str += '<li class="BTN" fromId="' + data1[i].fromId + '" style="cursor: pointer;text-align: left;height: 44px">' +
                                '<input id="' + data1[i].emailList[0].emailId + '" nId="' + data1[i].bodyId + '" readF="' + data1[i].emailList[0].readFlag + '" type="hidden" ueId="' + data1[i].emailList[0].deleteFlag + '">' +
                                '<input checkId="' + data1[i].bodyId + '" class="chekEmail" style="width:16px;display:none;" type="checkbox">' +
                                '<div class="shang" style="display: inline;">' +
                                '<span style="margin-left:2%">' + function () {
                                    if (dataId.flag == 'inbox') {
                                        return returnUserName(data1[i].users);
                                    } else if (dataId.flag == 'outbox') {
                                        if (data1[i].toName == '') {
                                            return toNameId[0];
                                        } else {
                                            return toNames[0];
                                        }
                                    } else {
                                        return data1[i].users.userName;
                                    }
                                }() + '</span>' +
                                function () {
                                    if (boxStyle == 'inbox' || boxStyle == 'unreadBox') {
                                        if (data1[i].emailList[0].readFlag == '1') {
                                            // return '<img src="../img/readed.png"/>';
                                            return '';
                                        } else {
                                            return '<span class="fa fa-envelope noReadF" ></span>';
                                        }
                                    } else {
                                        // return '<img src="../img/readed.png"/>';
                                        return '';
                                    }
                                }() +
                                '<span class="time">' + sendTime + '</span>' +
                                '</div>' +
                                '<div class="xia">' +
                                '<span style="float: left;margin-left: 13px;margin-right: 4px;">' + function () {
                                    if (data1[i].attachmentId != '' && data1[i].emailList[0].withdrawFlag != '1') {
                                        /*return '<img src="/img/main_img/accessory.png" style="margin-right:85.8%;width: 11px;height: 15px;"/>';*/
                                        return '<i class="fa fa-paperclip"></i>';
                                    } else {
                                        return '';
                                    }
                                }() + '</span>' +
                                '<a class="xia_txt" href="javascript:;" style="width: 96%;-webkit-line-clamp:2;overflow: hidden;display: -webkit-box;-webkit-box-orient: vertical;margin-left: 10px">' + emailSubject + '</a>' +
                                '</div>' +
                                '</li>';
                        }
                        $('.befor').html(str);
                        $('li.BTN').eq(0).addClass("backing");
                        var emailId = $('.befor .backing').find('input[type="hidden"]').attr('id');
                        var bodyNid = $('.befor .backing').find('input').attr('nId');
                        if (boxStyle == 'inbox' || boxStyle == 'unreadBox') {
                            var formIds = $('.befor .backing').attr('fromid');
                            var detailData = {
                                emailId: emailId,
                                flag: ''
                            }
                            $('.detailes').show();
                            $('.drafts').hide();
                            getUserInfo_s(formIds);
                            initData(detailData);
                        } else if (boxStyle == 'drafts') {
                            $('.detailes').hide();
                            $('.drafts').show();
                            initDrafts(bodyNid);

                        } else if (boxStyle == 'outbox') {
                            $('.getUser').hide();
                            $('.detailes').show();
                            $('.drafts').hide();
                            var detailOutbox = {
                                bodyId: bodyNid,
                                flag: ''
                            }
                            initData(detailOutbox);
                        } else if (boxStyle == 'recycle') {

                            $('.getUser').hide();
                            $('.detailes').show();
                            $('.drafts').hide();
                            var detailRecycle = {
                                emailId: emailId,
                                flag: ''
                            }
                            initData(detailRecycle);
                        } else if (boxStyle == 'otherBox') {
                            $('.getUser').hide();
                            $('.detailes').show();
                            $('.drafts').hide();
                            var detailOtherBox = {
                                emailId: emailId,
                                flag: ''
                            }
                            initData(detailOtherBox);
                        }
                    } else {
                        $('.befor').hide();
                        $('.noContent').show();
                        $('.noEmail').show().siblings().hide();
                    }
                }
            })

        },
        pageTwo: function (totalData, pageSize, indexs) {
            var mes = this;
            $('#dbgz_page').pagination({
                totalData: totalData,
                showData: pageSize,
                jump: true,
                coping: true,
                homePage: '',
                endPage: '',
                current: indexs || 1,
                callback: function (index) {
                    mes.data.page = index.getCurrent();
                    mes.page();
                }
            });
        }
    };
    ajaxPage.page();
}


//获取人员图像、信息接口
function getUserInfo_s(id) {
    $.ajax({
        type: 'get',
        url: '../user/findUserByuserId',
        dataType: 'json',
        data: {'userId': id},
        success: function (res) {
            if (res.flag == true) {
                var dataU = res.object;
                $('.zong').text(dataU.userPrivName);
                $('.userdept').text(dataU.deptName);
                $('.span_hr').find('p').find('span').eq(0).html(dataU.userName);
                if (dataU.avatar == '' || dataU.avatar == undefined) {
                    $('.attrImg img').attr('src', '../img/email/icon_head_man_06.png');
                } else if (dataU.avatar == 0) {
                    $('.attrImg img').attr('src', '../img/email/icon_head_man_06.png');
                } else if (dataU.avatar == 1) {
                    $('.attrImg img').attr('src', '../img/email/icon_head_woman_06.png');
                } else {
                    $('.attrImg img').attr('src', '../../img/user/' + dataU.avatar);
                }
            }

        }
    })
}
//获取地址栏参数
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null)return unescape(r[2]);
    return null
}
<!-- 处理姓名为空处理 /users处理 -->
function returnUserName(users) {
    if (users == undefined || users == "") {
        return ""
    } else {
        return users.userName
    }
}
//查看邮件状态
function lookemail(e) {
    var urls = e.attr('urls');
    var name = '<fmt:message code="event.th.ViewMailStatus" />';
    if (typeof(qt) == 'undefined') {
        window.open(urls);
    } else {
        new QWebChannel(qt.webChannelTransport, function (channel) {
            var content = channel.objects.interface;
            content.xoa_sms(urls, name, "web_child_url")
        })
    }
}
